<div class="easyui-layout" data-options="fit:true">
    <!-- Begin of toolbar -->
    <div id="wu-toolbar-3">
        <div class="wu-toolbar-button">
            <!-- <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="openAddCom()" plain="true">添加</a> -->
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="openEditCom()" plain="true">修改</a>
            <!-- <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="removeCom()" plain="true">删除</a> -->
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="reloadCom()" plain="true">刷新</a>
        </div>
    </div>
    <!-- End of toolbar -->
    <table id="wu-datagrid-com" class="easyui-datagrid" toolbar="#wu-toolbar-3"></table>
</div>
<!-- Begin of easyui-dialog -->
<div id="wu-dialog-com" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:400px; padding:10px;">
    <form id="wu-form-com" method="post">
        <table>
            <tr>
                <td width="60" align="right">配置名称:</td>
                <td>
                    <input type="text" name="title" class="wu-text" required="required" disabled/>
                </td>
            </tr>
            <tr>
                <td align="right">配置属性:</td>
                <td>
                    <input type="text" name="content" class="wu-text" required="required"/>
                </td>
            </tr>
            <input type="text" name="id" style="display:none;">
        </table>
    </form>
</div>
<!-- End of easyui-dialog -->
<script type="text/javascript">
    /**
     * Name 添加记录
     */
    function add1() {
        $('#wu-form-com').form('submit', {
            url: $.webConfig.apiUrl + 'config/addconfig',
            success: function (data) {
                var data = JSON.parse(data);
                if (data['return_code']) {
                    $.messager.alert('信息提示', '提交成功！', 'info');
                    $('#wu-dialog-com').dialog('close');
                    $('#wu-datagrid-com').datagrid('reload');
                } else {
                    $.messager.alert('信息提示', '提交失败！', 'info');
                }
            }
        });
    }

    /**
     * Name 修改记录
     */
    function edit1() {
        $('#wu-form-com').form('submit', {
            url: $.webConfig.apiUrl + 'config/upconfig',
            success: function (data) {
                var data = JSON.parse(data);
                if (data['return_code'] == 1) {
                    $.messager.alert('信息提示', '提交成功！', 'info');
                    $('#wu-dialog-com').dialog('close');
                    $('#wu-datagrid-com').datagrid('reload');
                } else {
                    $.messager.alert('信息提示', '提交失败！', 'info');
                }
            }
        });
    }

    /**
     * Name 删除记录
     */
    function removeCom() {
        $.messager.confirm('信息提示', '确定要删除该记录？', function (result) {
            if (result) {
                var items = $('#wu-datagrid-com').datagrid('getSelections');
                var ids = [];
                $(items).each(function () {
                    ids.push(this.id);
                });

                if (!items) {
                    $.messager.alert('信息提示', '你没选中哦...', 'info');
                    return;
                }

                //alert(ids);return;
                $.ajax({
                    type: 'post',
                    url: $.webConfig.apiUrl + 'config/delconfig',
                    data: {
                        id: ids[0]
                    },
                    success: function (data) {
                        var data = JSON.parse(data);
                        if (data['return_code'] == 1) {
                            $.messager.alert('信息提示', '删除成功！', 'info');
                            $('#wu-datagrid-com').datagrid('reload');
                        } else {
                            $.messager.alert('信息提示', '删除失败！', 'info');
                        }
                    }
                });
            }
        });
    }

    /**
     * Name 打开添加窗口
     */
    function openAddCom() {
        $('#wu-form-com').form('clear');
        $('#wu-dialog-com').dialog({
            closed: false,
            modal: true,
            title: "添加信息",
            cache: false,
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: add1
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-com').dialog('close');
                }
            }]
        });
    }

    /**
     * Name 打开修改窗口
     */
    function openEditCom() {
        $('#wu-form-com').form('clear');
        var item = $('#wu-datagrid-com').datagrid('getSelected');

        if (!item) {
            $.messager.alert('信息提示', '你没选中哦...', 'info');
            return;
        }

        $('#wu-form-com').form('load', item);

        $('#wu-dialog-com').dialog({
            closed: false,
            modal: true,
            title: "修改信息",
            cache: false,
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: edit1
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-com').dialog('close');
                }
            }]
        });
    }

    /**
     * Name 分页过滤器
     */
    function pagerFilter(data) {
        var pageData = {
            total: 18,
            rows: []
        };

        if (data['return_code'] == 1) {
            if (data['total']) {
                pageData['total'] = data['total'];
            }
            pageData['rows'] = data['return_body'];
        }

        return pageData;
    }


    /**
     * Name 载入数据
     */
    $('#wu-datagrid-com').datagrid({
        url: $.webConfig.apiUrl + 'config/getconfig',
        loadFilter: pagerFilter,
        rownumbers: true,
        singleSelect: true,
        pageSize: 20,
        pagination: false,
        multiSort: true,
        fitColumns: true,
        fit: true,
        columns: [
            [{
                    checkbox: true
                },
                {
                    field: 'title',
                    title: '配置',
                    width: 100,
                    sortable: true
                },
                {
                    field: 'content',
                    title: '属性',
                    width: 180,
                    sortable: true
                }
            ]
        ]
    });

    // 刷新页面
    function reloadCom() {
        $('#wu-datagrid-com').datagrid('reload');
    }
</script>